package com.niji.littly_donkey_android.view;

import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;

/**
 * Des: 自定义PopupWindow
 *
 */
public class MyPopupWindow extends PopupWindow {

    public MyPopupWindow(View contentView, int width, int height, boolean b) {
        super(contentView, width, height, b);
    }

    @Override
    public void showAsDropDown(View anchor) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int heightPixels = anchor.getResources().getDisplayMetrics().heightPixels;
            int h = heightPixels - rect.bottom;
            //设置负值能达到自适应的效果
            setHeight(-20);
        }
        super.showAsDropDown(anchor);
    }
}